/**
 * 
 */
package com.local.jodatime.jodabase;

import java.util.Locale;

import org.joda.time.DateTime;
import org.joda.time.Months;
import org.joda.time.Period;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

/**
 * @author Administrator
 *
 */
public class SubDateTime {
    public void subTime() {
    	DateTime d1 = changeFormat("201012","yyyyMM");
    	DateTime d2 = changeFormat("201111","yyyyMM");
    	Period period=new Period(d1,d2);
    	System.out.println("相差"+(period.getYears()*12+period.getMonths())+"月");
    }
    
    public static DateTime changeFormat(String arg0,String format) {
    	DateTimeFormatter matter = DateTimeFormat.forPattern(format);  
		//时间解析  
    	DateTime dateTime = null;
		try{
			dateTime = DateTime.parse(arg0, matter);  
		}catch(Exception e){
			//throw new Exception("数据与原格式请务必一致！");
			dateTime = null;
		}
		return dateTime;
    }
    
    
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
         new SubDateTime().subTime();
	}

}
